package cn.xingyun.pickaxe_loli_new.command;

import net.minecraft.network.chat.Component;
import net.minecraft.util.ByIdMap;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.entity.player.Abilities;
import net.minecraft.world.level.GameType;
import org.jetbrains.annotations.Contract;

import javax.annotation.Nullable;
import java.util.function.IntFunction;

public enum ModeType implements StringRepresentable {
    NOSCREEN(0, "noscreen"),
    NOSPAWN(1, "nospawn"),
    UNCLEARABLE(2, "unclearable"),
    SPECTATOR(3, "empty");

    public static final StringRepresentable.EnumCodec<ModeType> CODEC = StringRepresentable.fromEnum(ModeType::values);
    private static final IntFunction<ModeType> BY_ID = ByIdMap.continuous(ModeType::getId, values(), ByIdMap.OutOfBoundsStrategy.ZERO);
    private static final int NOT_SET = -1;
    private final int id;
    private final String name;
    private final Component shortName;
    private final Component longName;

    private ModeType(int p_46390_, String p_46391_) {
        this.id = p_46390_;
        this.name = p_46391_;
        this.shortName = Component.translatable("selectWorld.gameMode." + p_46391_);
        this.longName = Component.translatable("gameMode." + p_46391_);
    }

    public int getId() {
        return this.id;
    }

    public String getName() {
        return this.name;
    }

    public String getSerializedName() {
        return this.name;
    }

    public Component getLongDisplayName() {
        return this.longName;
    }

    public Component getShortDisplayName() {
        return this.shortName;
    }

    public void updatePlayerAbilities(Abilities p_46399_) {
       /*if (this == NOSPAWN) {
//            p_46399_.mayfly = true;
//            p_46399_.instabuild = true;
//            p_46399_.invulnerable = true;
//        } else if (this == SPECTATOR) {
//            p_46399_.mayfly = true;
//            p_46399_.instabuild = false;
//            p_46399_.invulnerable = true;
//            p_46399_.flying = true;
//        } else {
//            p_46399_.mayfly = false;
//            p_46399_.instabuild = false;
//            p_46399_.invulnerable = false;
//            p_46399_.flying = false;
        }

        p_46399_.mayBuild = !this.isBlockPlacingRestricted();*/
    }

    public boolean isBlockPlacingRestricted() {
        return this == UNCLEARABLE || this == SPECTATOR;
    }

    public boolean isNospawn() {
        return this == NOSPAWN ;
    }

    public boolean isnoScreen() {
        return this == NOSCREEN;
    }
    public boolean isUncleable() {
        return this == NOSCREEN;
    }

    public static ModeType byId(int p_46394_) {
        return BY_ID.apply(p_46394_);
    }

    public static ModeType byName(String p_46401_) {
        return byName(p_46401_, NOSCREEN);
    }

    @Nullable
    @Contract("_,!null->!null;_,null->_")
    public static ModeType byName(String p_46403_, @Nullable ModeType p_46404_) {
        ModeType gametype = CODEC.byName(p_46403_);
        return gametype != null ? gametype : p_46404_;
    }

    public static int getNullableId(@Nullable ModeType p_151496_) {
        return p_151496_ != null ? p_151496_.id : -1;
    }

    @Nullable
    public static ModeType byNullableId(int p_151498_) {
        return p_151498_ == -1 ? null : byId(p_151498_);
    }
}